package net.jblog.business.facade.impl;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import net.jblog.business.IConstantes;
import net.jblog.business.dao.AdministratorUserDao;
import net.jblog.business.dao.CategoryDao;
import net.jblog.business.dao.CounterDao;
import net.jblog.business.dao.ParameterDao;
import net.jblog.business.facade.InitializeFacade;
import net.jblog.data.model.AdministratorUser;
import net.jblog.data.model.Category;
import net.jblog.data.model.Parameter;

public class InitializeFacadeImpl implements InitializeFacade, IConstantes {
	private Logger log = Logger.getLogger(InitializeFacadeImpl.class.getName());
	private AdministratorUserDao administratorUSerDao;
	private CategoryDao categoryDao;
	private CounterDao counterDao;
	private ParameterDao parameterDao;
	
	@Override
	public void initializeAdministrator(AdministratorUser entity) {
		log.log(Level.INFO, "Initialization administrator");
		getAdministratorUSerDao().persist(entity);
	}
	
	public void initializeGeneralCategory(Category entity) {
		log.log(Level.INFO, "Initialization category General");
		Long id = COUNTER_INITIALIZE;
		Key key = KeyFactory.createKey(Category.class.getSimpleName(), id);
		entity.setId(id);
		entity.setKey(key);
		getCategoryDao().persist(entity);
	}
	
	public void initializeParameters(List<Parameter> parameters) {
		log.log(Level.INFO, "Initialization parameters");
		for (Parameter parameter : parameters) {
			Key key = KeyFactory.createKey(Parameter.class.getSimpleName(), parameter.getCle());
			parameter.setKey(key);
			getParameterDao().persist(parameter);
		}
	}

	public AdministratorUserDao getAdministratorUSerDao() {
		return administratorUSerDao;
	}

	public void setAdministratorUSerDao(AdministratorUserDao administratorUSerDao) {
		this.administratorUSerDao = administratorUSerDao;
	}

	public CategoryDao getCategoryDao() {
		return categoryDao;
	}

	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}
	public CounterDao getCounterDao() {
		return counterDao;
	}
	public void setCounterDao(CounterDao counterDao) {
		this.counterDao = counterDao;
	}

	public ParameterDao getParameterDao() {
		return parameterDao;
	}

	public void setParameterDao(ParameterDao parameterDao) {
		this.parameterDao = parameterDao;
	}

	
	
}
